/*
Sader engine framework
(c) Rachel J. Morris
MIT License
www.moosader.com
*/

#ifndef _Sader_ManagerTemplate
#define _Sader_ManagerTemplate

#include <string>
#include <vector>

namespace sader
{
    template <class ITEM>
    class ManagerTemplate
    {
        public:
        ITEM& GetAsset( std::string name )
        {
            unsigned int index = FindAsset( name );

            if ( index < m_items.size() && index >= 0 );
                return m_items[index];
        }

        ITEM& GetAsset( unsigned int index )
        {
			if ( index < m_items.size() && index >= 0 );
				return m_items[index];
		}


        int FindAsset( std::string name )
        {
			for ( unsigned int i=0; i<m_items.size(); i++ )
			{
				if ( m_items[i].m_name == name )
				  return i;
			}
			return -1;
		}

        void AddAsset( ITEM item )
        {
			m_items.push_back( item );
		}

        protected:
        std::vector< ITEM > m_items;
        void LoadAssetsFromFile( std::vector<std::string> assetList )
        {
			for ( std::vector<std::string>::const_iterator filepath = assetList.begin();
					filepath != assetList.end();
					++filepath )
			{
				ITEM temp;
				temp.m_name = (*filepath).substr( 0, (*filepath).size() - 4 ); // assuming file extention no longer than 3 chars

				if ( temp.Load( (std::string&)(*filepath) ) )
				{
					m_items.push_back( temp );
				}
			}
		}
    };
}

#endif
